<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-6-8
 * Time: 16:29
 */

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Factor;
use app\common\model\Fenorder;
use app\common\model\Newscat;
use think\Db;

/**
 * 前台首页控制器
 * @package app\index\controller
 */
class Notic extends Auth
{
    public $noNeedLogin = [];

    /**
     * 获取公告列表
     */
    public function lists()
    {
        if ($this->request->isPost()) {
            $getData = $this->request->post();
            if (empty($getData['page'])) {
                $getData['page'] = 1;
            }
            $pageData = $this->request->get('limit');
            if(empty($pageData) || !isset($pageData)){
                $limit = 10;
            }else{
                $limit = $pageData;
            }
            $noticData = Db::name('qt_notic')
                ->field('id,title,desc,created_time')
                ->where('store_id',$this->userInfo['store_id'])
                ->order('id desc')
                ->paginate($limit);
            $this->result('查询成功', $noticData, 200);
        }
        $this->result('请求参数有误', '', 204);


    }

    /**
     * 获取公告详情
     */

    public function detail()
    {
        if ($this->request->isPost()) {
            $getData = $this->request->post();
            if (empty($getData['id'])) {
                $this->result('请求参数有误', '', 204);
            }
            $noticData = Db::name('qt_notic')
                ->field('id,title,desc,created_time,content')
                ->where(['id'=>$getData['id']])
                ->find();
            $this->result('查询成功', $noticData, 200);
        }
        $this->result('请求参数有误', '', 204);
    }


}
